<template>
  <a-button type="primary" @click="onClick" :disabled="disabled">
    新建文件夹
  </a-button>
</template>
<script setup>
import { computed } from 'vue'
import {
  useDataSourceManager,
  useTreeSelectedInfo,
  useCreateFolderDisabled,
  useRowSelectionActive,
  useLockForInUse,
} from './provide-context.js'
/**
 * 全局
 */
let { createEmpty } = useDataSourceManager()
let treeSelectedInfo = useTreeSelectedInfo()
let createFolderDisabled = useCreateFolderDisabled()
let rowSelection = useRowSelectionActive()
let lockForInUse = useLockForInUse()

/**
 * 锁标识
 */
let lockSymbol = Symbol('new-folder')
/**
 * 开始创建
 */
function onClick() {
  lockForInUse.value = lockSymbol

  // if (createing.value) return
  createEmpty()
}
/**
 * 是否在创建中
 */
// let createing = computed(() =>
//   dataSource.value.some(({ editing }) => editing === true),
// )
let disabled = computed(() => {
  return (
    !treeSelectedInfo.value ||
    (treeSelectedInfo.value.children || []).length > 0 ||
    createFolderDisabled ||
    // createing.value ||
    !!lockForInUse.value ||
    rowSelection.value
  )
})
</script>
